<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>航空附加费用管理</title>
    <% include("/common/common_css_js.html"){} %>
</head>
<body>
    <div style="padding-bottom: 5px;">
        <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
            <span>航空公司名称：</span>
            <input id="queryFormAirlinesId" name="airlinesId" class="mini-combobox" style="width:250px;" textField="name" valueField="id" emptyText="请选择..."
                   required="false" allowInput="true" showNullItem="true" nullItemText="请选择..." requiredErrorText=""/>

            <span class="separator"></span>
            <% if(so.hasPermission("xtAairlinesAddCostDetail:query")){%>
                <a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
            <% } %>

            <% if(so.hasPermission("xtAairlinesAddCostDetail:queryCndClear")){%>
                <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
            <% } %>

            <span class="separator"></span>
            <% if(so.hasPermission("xtAairlinesAddCostDetail:add")){%>
                <a class="mini-button" iconCls="icon-add" onclick="add()">新增</a>
            <% } %>

            <% if(so.hasPermission("xtAairlinesAddCostDetail:edit")){%>
            <a class="mini-button" iconCls="icon-edit" onclick="update()">编辑</a>
            <% } %>

            <% if(so.hasPermission("xtAairlinesAddCostDetail:delete")){%>
                <a class="mini-button" iconCls="icon-remove" onclick="deleteAirlineAddCostDetail()">删除</a>
            <% } %>
        </div>
    </div>

    <div class = "mini-fit">
        <div id="datagrid1" class="mini-datagrid"
             style="width: 100%; height: 100%;"
             url="${base}/pages/basic_data_manage/xt_airlines/add_cost_detail/query" idField="id"
             showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
             allowResize="true"
             allowCellWrap="true">
            <div property="columns">
<!--                <div field="id" width="140" headerAlign="center" align="left" allowSort="true">表ID</div>-->
                <div field="airlinesId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airlines"}' renderer="commonRender">航空公司名称</div>
                <div field="name" width="140" headerAlign="center" align="center" allowSort="true">附加费用名称</div>
                <div field="price" width="140" headerAlign="center" align="center" allowSort="true">附加费用单价</div>
                <div field="ticketPrice" width="140" headerAlign="center" align="center" allowSort="true">附加费用起票价</div>
                <div field="comment" width="140" headerAlign="center" align="center" allowSort="true">说明</div>
            </div>
        </div>
    </div>

    <!--编辑窗口-->
    <div id="updatePanel" class="mini-window" title="航空附加费用管理" style="width:800px;height:500px;"
         showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
         showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
        <div property="footer" style="padding:10px;text-align: right">
            <a  id="insertOrUpdateSaveBtn" name="insertOrUpdateSaveBtn" class="mini-button" iconCls="icon-save" onclick="saveInsertOrUpdate()">保存</a>
        </div>
        <div id="airlinesAddCostForm">
            <input name="id" class="mini-hidden"/>
            <table style="width: 100%">
                <tr>
                    <td><label>航空公司:</label></td>
                    <td><input id="airlinesId" name="airlinesId" class="mini-combobox" style="width:250px;" textField="name" valueField="id" emptyText="请选择..."
                           required="true" allowInput="true" showNullItem="true" nullItemText="请选择..." requiredErrorText=""/>
                    </td>
                </tr>
                <tr>
                    <td><label>附加费用名称:</label></td>
                    <td>
                        <input name="name" class="mini-textbox" required="true" emptyText="附加费用名称"/>
                    </td>
                </tr>
                <tr>
                    <td><label>单价(元/公斤):</label></td>
                    <td colspan="3">
                        <input name="price" class="mini-textbox" emptyText="单价(元/公斤)" required="true" vtype="float"/>
                        <label>起票价:</label>
                        <input name="ticketPrice" class="mini-textbox" emptyText="起票价" required="true" vtype="float"/>
                    </td>
                </tr>
                <tr>
                    <td><label>备注:</label></td>
                    <td colspan="3"><input name="comment" class="mini-textarea" required="false" requiredErrorText="备用不能为空" style="width:508px;height: 60px;"/></td>
                </tr>
            </table>
        </div>
    </div>

    <script type="text/javascript">
        mini.parse();
        let grid = mini.get("datagrid1");
        let oper;
        let airlinesAddCostForm = new mini.Form("#airlinesAddCostForm");

        $(function () {
            // 加载列表数据
            grid.load();

            //新增、修改弹出框默认操作
            oper = OPER_ADD();

            // 加载弹出窗口的有效性下拉列表  airlines
            let jsonData = commonRenderDropList("airlines");
            mini.get("airlinesId").load(jsonData);
            mini.get("queryFormAirlinesId").load(jsonData);

        });

        function search() {
            let form = new mini.Form("#queryForm");
            let data = form.getData(true);
            grid.load(data);
        }

        function clearSearch() {
            let form = new mini.Form("#queryForm");
            form.clear();
        }

        function add(){
            airlinesAddCostForm.clear();
            oper = OPER_ADD();
            // 弹出添加窗口
            public_showModelAtPos("updatePanel", "center", "middle");
        }

        function update(){
            airlinesAddCostForm.clear();
            // 获取当前选中的行
            let row = grid.getSelected();
            if(!row){
                mini.alert("请选择要编辑的行!","航空附加费用管理",null);
                return;
            }
            airlinesAddCostForm.setData(row);

            oper = OPER_UPDATE();
            // 弹出添加窗口
            public_showModelAtPos("updatePanel", "center", "middle");

        }


        //新增保存或修改保存
        function saveInsertOrUpdate(){
            // 添加并保存
            airlinesAddCostForm.validate();
            if (airlinesAddCostForm.isValid() == false){
                public_showErrorTips("请将信息填写完整再进行下一步！");
                return;
            }
            let data = airlinesAddCostForm.getData(true);

            mini.confirm(
                "确定保存附加费?",
                "保存提示",
                function(action) {
                    if (action == "ok") {
                        let methodName = oper == OPER_ADD() ? "insert" : "update";
                        let ret = public_getServerData("${base}/pages/basic_data_manage/xt_airlines/add_cost_detail/" + methodName,data);
                        showAlert(ret.message,function (){
                            if(ret.ok){
                                // 重新刷新数据
                                grid.reload();
                                public_onCancel('updatePanel');
                            }
                        });
                    }
                });


        }

        function deleteAirlineAddCostDetail(){
            let select = grid.getSelected();
            if(select == null){
                public_showErrorTips("未选中");
                return;
            }
            mini.confirm(
                "确定删除附加费?",
                "删除提示",
                function(action) {
                    if (action == "ok") {
                        let ret = public_getServerData("${base}/pages/basic_data_manage/xt_airlines/add_cost_detail/delete",select.id);
                        public_showTip(ret);
                        if(ret.ok) {
                            // 重新刷新数据
                            grid.removeRow(select, true);
                        }
                    }
                });
        }

    </script>
</body>
</html>